/**
 * @Method radio
 * @Description TODO
 * @Date 2021/1/20 9:52
 * @Created by HePing
 */
export default {
  model: {
    prop: 'model'
  },
  props: {
    model: {},
    config: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  render(h) {
    const vm = this
    const {
      widget: { style, nativeOn, groupProps, props, attrs, className },
      dict
    } = vm.config
    const children = ({ list, label = 'label', value = 'value' }) => list.map(cell => {
      return h(
        props && props.type === 'button' ? 'el-radio-button' : 'el-radio',
        {
          attrs,
          props: {
            ...props,
            name: cell.name,
            label: cell[value]
          }
        },
        [
          cell[label]
        ]
      )
    })
    return h(
      'el-radio-group',
      {
        attrs,
        style,
        props: {
          ...groupProps,
          value: vm.model
        },
        on: vm.$listeners,
        nativeOn,
        class: className
      },
      children(dict)
    )
  }
}
